package com.example.springboot_system.Controller;

import com.example.springboot_system.service.AnnounceService;
import com.example.springboot_system.utils.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("/Announce")
public class AnnounceController {
    @Autowired
    private AnnounceService announceService;

    @RequestMapping("/findAnnounce")
    @ResponseBody
    public ResponseResult findAnnounce(String hiddenId){
        ResponseResult result = announceService.findAnnounceById(hiddenId);
        return result;
    }

    @RequestMapping("/deleteAnnounceById")
    @ResponseBody
    public ResponseResult deleteAnnounceById(String hiddenId, HttpSession session){
        ResponseResult result = announceService.deleteAnnounceById(hiddenId,session);
        announceService.findAllAnnounce(session);
        return result;
    }

    @RequestMapping("/updateAnnounceById")
    @ResponseBody
    public ResponseResult updateAnnounceById(String hiddenId,String title,String contents, HttpSession session){
        ResponseResult result = announceService.updateAnnounceById(hiddenId,title,contents,session);
        announceService.findAllAnnounce(session);
        return result;
    }

    @RequestMapping("/addAnnounce")
    @ResponseBody
    public ResponseResult addAnnounce(String addTitle,String addContents, HttpSession session){
        ResponseResult result = announceService.addAnnounce(addTitle,addContents,session);
        announceService.findAllAnnounce(session);
        return result;
    }

    @RequestMapping("/setAnnStatus0")
    @ResponseBody
    public ResponseResult setAnnStatus0(String hiddenId, HttpSession session){
        ResponseResult result = announceService.setAnnStatus0(hiddenId,session);
        announceService.findAllAnnounce(session);
        return result;
    }

    @RequestMapping("/setAnnStatus1")
    @ResponseBody
    public ResponseResult setAnnStatus1(String hiddenId, HttpSession session){
        ResponseResult result = announceService.setAnnStatus1(hiddenId,session);
        announceService.findAllAnnounce(session);
        return result;
    }
}
